package com.chen.hotel.Service.impl;

import com.chen.hotel.Service.HotelService;
import com.chen.hotel.dao.HotelDao;
import com.chen.hotel.domain.Hotel;
import com.chen.hotel.utils.CopyNotNullUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
public class HotelServiceImpl implements HotelService {
    @Autowired
    private HotelDao dao;


    @Override
    public Hotel findOne(Integer id) {
        return this.dao.findById(id).get();
    }

    @Override
    public Hotel create(Hotel hotel) {
        return this.dao.save(hotel);
    }

    @Override
    public void delete(Integer id) {
        this.dao.deleteById(id);
    }

    @Override
    public Hotel update(Hotel hotel) {
        Hotel h = this.findOne(hotel.getId());
        h = CopyNotNullUtil.copyNoNullProperties(hotel, h);
        return this.dao.save(h);
    }
}
